package com.example.otto.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.otto.DTO.CommentDTO;
import com.example.otto.DTO.UserLoginDTO;
import com.example.otto.entity.Manager;
import com.example.otto.entity.Task;
import com.example.otto.entity.User;
import com.example.otto.mapper.UserMapper;
import com.example.otto.service.TaskService;
import com.example.otto.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private UserService userService;

    @PostMapping
    public int save(@RequestBody User user){
        return userService.save(user);
    }

    @GetMapping
    public List<User> findAll() {
        List<User> all = userMapper.findAll();
        return all;
    }

    @DeleteMapping("/{id}")
    public int delete(@PathVariable Integer id){
        return userMapper.deleteById(id);
    }

    @GetMapping("/page")
    public List<User> findPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize){
        pageNum = (pageNum-1) * pageSize;
        return userMapper.selectPage(pageNum,pageSize);
    }

    @PostMapping("/login")
    public ResponseEntity<?> login(@RequestBody User user){
        return userService.loginService(user);
    }


    @PutMapping("/comment")
    public boolean submitComment(@RequestBody CommentDTO commentDTO){
        return userMapper.submitComment(commentDTO);
    }
}
